<%@ page import="com.ewentsai.Article" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="com.ewentsai.DB" %>
<%--
  Created by IntelliJ IDEA.
  User: 60567
  Date: 2019/3/5
  Time: 20:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        .header{
            width: 100%;
            height: 10%;
            background-color: black;
        }
        .toolbar-style{
            height: 3%;
            background-color: beige;
        }
        .header-button{
            width: 40%;
            height: 50px;
            margin: 0 auto;
            float: right;
        }
        .user-photo{
            width: 20%;
            height: 20%;
            background-color: darkgrey;
            float: left;
        }
        .title{
            width: 100%;
            height: 15%;
            background-color: cornflowerblue;
        }
        .content{
            width: 80%;
            height: 20%;
            float: right;
        }
        .button-style{
            display: inline-block;
            border-radius: 4px;
            background-color: darkgrey;
            border: none;
            color: #FFFFFF;
            text-align: center;
            font-size: 16px;
            padding: 15px;
            width: 10%;
            transition: all 0.5s;
            cursor: pointer;
            margin: 3%;
        }
    </style>
    <title>帖子详情</title>
</head>
<body>
<%
    int id = Integer.parseInt(request.getParameter("id"));
    ArrayList<Article> articles = new ArrayList<>();
    Connection connection = DB.getConnection();
    Statement statement = DB.createStatement(connection);
    ResultSet rSet = DB.executeQuery(statement, "select * from article");
    int index = -1;
    while (rSet.next()){
        Article article = new Article();
        article.getInitFormRS(rSet);
        articles.add(article);
        if(article.getId()==id){
            index = articles.size()-1;
        }
    }
%>
<%
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    int pid = articles.get(index).getPid();
    int[] ArticleList = new int[100];
    int j = 0;
        for(int i=0 ; i<articles.size(); i++){
            int Parentid = articles.get(i).getPid();
            if(Parentid==pid){
                ArticleList[j] = i;
                j++;
            }
        }
%>
<%
    String loginUserName;
    loginUserName = request.getParameter("loginUserName");
    if(loginUserName==null){
        loginUserName = "登录";
    }
%>
<div class="header">
    <font size="22" color="white">Blog</font>
    <header class="header-button">
        <a href="login.jsp"><button class="button-style"><span><%= loginUserName%></span></button></a>
        <a href="RegisterPage.jsp"><button class="button-style"><span>注册</span></button></a>
    </header>
</div>
<div class="toolbar-style">
    <a href="reply.jsp?loginUserName=<%= loginUserName %>&pid=<%= pid%>&size=<%= articles.size()%>">回复帖子</a>
</div>
<%
    for(int i=0; i<=j; i++){
%>
<div class="user-photo">
    <%= articles.get(i).getAuthor()%><br>
    <%= articles.get(i).getCreateTime().toString()%>
</div>
<div class="content">
    <div class="title"><%= articles.get(i).getTitle()%></div>
    <%= articles.get(i).getContent()%>
</div>
<%
    }
%>
</body>
</html>
